<?php
/**
 * Created by PhpStorm.
 * User: BlueIdeaLirui
 * Date: 2019/09/05
 * Time: 17:24
 */

namespace search\controllers\marketDataAnalysis;

use business\base\models\ResultModel;
use yii\web\Controller;

class BaseController extends Controller
{
    /**
     * 错误返回
     * @param $code
     * @param $message
     * @return ResultModel
     */
    protected function error($code, $message = '')
    {
        $resultModel = new ResultModel();
        $resultModel->success = false;
        $resultModel->errorCode = $code;
        $resultModel->message = $message;
        return $resultModel;
    }

    /**
     * 成功返回
     * @param $data
     * @return ResultModel
     */
    protected function success($data = [])
    {
        $resultModel = new ResultModel();
        $resultModel->success = true;
        $resultModel->data = $data;
        return $resultModel;
    }

    protected function getParam($key, $type = 'get', $default = '')
    {
        if ($type == 'get') {
            return \Yii::$app->request->get($key, $default);
        } else {
            return \Yii::$app->request->post($key, $default);
        }
    }
}
